//Binary_tree.h

#ifndef BINARY_TREE_H
#define BINARY_TREE_H

#include <stdio.h>
#include <stdlib.h>

typedef enum {N_LEAF, N_INTERNAL } nodetype_t;

//二叉树的节点对象
typedef struct node_t{
    nodetype_t type;
    /*使用联合体优化内存，这里internal.left和data[0]为互斥关系,internal.right和data[1]为互斥关系
    这个机制仅适用于64位系统*/
    union {
        struct
        {
            struct node_t *left;    //8字节
            struct node_t *right;   //8字节
        }internal;
        double data[2];   //16字节
    } info;
} Node;


// AVL树节点扩展
typedef struct avl_node_t {
    nodetype_t type;
    int key;
    int height;
    union {
        struct
        {
            struct avl_node_t *left;    //8字节
            struct avl_node_t *right;   //8字节
        }internal;
        double data[2];   //16字节
    } info;
} AVLNode;


typedef struct {
    Node* root;
    unsigned int node_count;
} Tree;



typedef struct {
    Node* root;
    unsigned int node_count;
} AVL_Tree;



// 树管理器（类似矩阵管理器）
typedef struct {
    Tree** trees;
    unsigned int Normal_count;
    unsigned int Normal_max_size;

    AVL_Tree** avl_trees;
    unsigned int avl_count;
    unsigned int avl_max_size;

    unsigned int all_count;
} TreeManager;




#include "Binary_tree.c"
#endif

